//
//  LGHomeMonitoringController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/1.
//  肺癌 -- 患者档案-居家监测

#import "LGCancerMonitoringController.h"
//体温、血氧、体重
#import "LGCancerPatientChartController.h"
//血压
#import "LGBloodPressureController.h"
//血糖
#import "LGBloodGlucoseController.h"
//症状
#import "LGCancerPatientSymptomController.h"

#define baseTop   viewPix(54)

@interface LGCancerMonitoringController ()<UIScrollViewDelegate>
/**   */
@property (nonatomic , strong)LGNavigationView *navigationView;
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)LGBloodPressureController *pressureVC;
/**   */
@property (nonatomic , strong)LGCancerPatientChartController *temperatureVC;
/**   */
@property (nonatomic , strong)LGCancerPatientChartController *oxygenVC;
/**   */
@property (nonatomic , strong)LGBloodGlucoseController *glucoseVC;
/**   */
@property (nonatomic , strong)LGCancerPatientChartController *weightVC;
/**   */
@property (nonatomic , strong)LGCancerPatientSymptomController *symptomVC;
/**   */
@property (nonatomic , strong)NSMutableArray *controllerArray;
/**   */
@property (nonatomic , strong)NSArray *titleArray;

@end

@implementation LGCancerMonitoringController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self commonInit];
    self.selectIndex = self.currentIndex;
    [self reloadData];
    self.scrollView.backgroundColor = [UIColor clearColor];
}

-(void)backButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark
#pragma mark ====> WMPageControllerDelegate
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titleArray.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titleArray[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    return self.controllerArray[index];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat count = self.titleArray.count>5?4.5:self.titleArray.count;
    return (Screen_W-20)/count;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, topBarHeight, Screen_W, viewPix(44));
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    return CGRectMake(0, topBarHeight+viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44));
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    LGBaseViewController *controller = (LGBaseViewController *)viewController;
    [controller viewWillAppearAction];
    NSLog(@">>>>>willEnterView>>>%@",viewController.title);
}

- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSLog(@">>>>>didEnterView>>>%@",viewController.title);
}

-(void)commonInit{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = kNavBgColor;
    [self.view addSubview:self.navigationView];
    //diseaseCode：1-房颤 、 2-肺癌 、 3-肺结节 、 4-食管癌
    if ([self.diseaseCode isEqualToString:@"3"]||[self.diseaseCode isEqualToString:@"6"]) {
        //肺结节没有血糖 、 体重
        self.titleArray = @[@"血压心率",@"体温",@"血氧",@"症状"];
        [self addChildViewController:self.pressureVC];
        [self addChildViewController:self.temperatureVC];
        [self addChildViewController:self.oxygenVC];
        [self addChildViewController:self.symptomVC];
        [self.controllerArray addObject:self.pressureVC];
        [self.controllerArray addObject:self.temperatureVC];
        [self.controllerArray addObject:self.oxygenVC];
        [self.controllerArray addObject:self.symptomVC];
    
    }else if ([self.diseaseCode isEqualToString:@"2"]||[self.diseaseCode isEqualToString:@"4"]) {
        //肺癌、食管癌
        self.titleArray = @[@"血压心率",@"体温",@"血氧",@"血糖",@"体重",@"症状"];
        [self addChildViewController:self.pressureVC];
        [self addChildViewController:self.temperatureVC];
        [self addChildViewController:self.oxygenVC];
        [self addChildViewController:self.glucoseVC];
        [self addChildViewController:self.weightVC];
        [self addChildViewController:self.symptomVC];
        [self.controllerArray addObject:self.pressureVC];
        [self.controllerArray addObject:self.temperatureVC];
        [self.controllerArray addObject:self.oxygenVC];
        [self.controllerArray addObject:self.glucoseVC];
        [self.controllerArray addObject:self.weightVC];
        [self.controllerArray addObject:self.symptomVC];
    
    }else{
        self.titleArray = @[@"血氧",@"血压心率",@"体重",@"症状"];
        [self addChildViewController:self.oxygenVC];
        [self addChildViewController:self.pressureVC];
        [self addChildViewController:self.weightVC];
        [self addChildViewController:self.symptomVC];
        
        [self.controllerArray addObject:self.oxygenVC];
        [self.controllerArray addObject:self.pressureVC];
        [self.controllerArray addObject:self.weightVC];
        [self.controllerArray addObject:self.symptomVC];
    }
    self.titleColorNormal = [UIColor colorWithString:@"#666666"];
    self.titleColorSelected = [UIColor colorWithString:@"#4C87FD"];
    self.progressColor = [UIColor colorWithString:@"#3291FF"];
    self.menuViewStyle=WMMenuViewStyleLine;
    self.titleFontName = @"STHeitiTC-Medium";
    self.titleSizeSelected = 16;
    self.titleSizeNormal = 14;
    self.progressWidth = viewPix(13);
    self.progressHeight = 4;
    self.progressViewBottomSpace = 0;
    self.progressViewCornerRadius = 2;
    self.selectIndex = 1;
    [self reloadData];
    self.scrollView.backgroundColor = [UIColor clearColor];
}

-(NSMutableArray *)controllerArray{
    if(!_controllerArray){
        _controllerArray = [NSMutableArray array];
    }
    return _controllerArray;
}

-(CAGradientLayer *)gradientLayer{
    if(!_gradientLayer){
        _gradientLayer = [CAGradientLayer layer];
        _gradientLayer.frame = CGRectMake(0,topBarHeight,Screen_W,viewPix(167));
        _gradientLayer.startPoint = CGPointMake(0.5, 0);
        _gradientLayer.endPoint = CGPointMake(0.5, 1.03);
        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F3FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#FEFEFF" alpha:0].CGColor];
        _gradientLayer.locations = @[@(0), @(0.4f), @(1.0f)];
    }
    return _gradientLayer;
}

-(LGNavigationView *)navigationView{
    if(!_navigationView){
        _navigationView = [[LGNavigationView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, topBarHeight)];
        _navigationView.backgroundColor = [UIColor colorWithString:@"#E5F3FF"];
        _navigationView.title = @"体征监测";
        [_navigationView.backBtn addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _navigationView;
}

-(LGBloodPressureController *)pressureVC{
    if(!_pressureVC){
        _pressureVC = [[LGBloodPressureController alloc] init];
        _pressureVC.patientid = self.patientid;
    }
    return _pressureVC;
}

-(LGCancerPatientChartController *)temperatureVC{
    if(!_temperatureVC){
        _temperatureVC = [[LGCancerPatientChartController alloc] init];
        _temperatureVC.chartAction = @"/doctor/patient.Physicalsign/tEcharts";
        _temperatureVC.recordAction = @"/doctor/patient.Physicalsign/tList";
        _temperatureVC.patientid = self.patientid;
        _temperatureVC.type = @"temperature";
    }
    return _temperatureVC;
}

-(LGCancerPatientChartController *)oxygenVC{
    if(!_oxygenVC){
        _oxygenVC = [[LGCancerPatientChartController alloc] init];
        _oxygenVC.chartAction = @"/doctor/patient.Physicalsign/spoEcharts";
        _oxygenVC.recordAction = @"/doctor/patient.Physicalsign/spoList";
        _oxygenVC.patientid = self.patientid;
        _oxygenVC.type = @"oxygen";
    }
    return _oxygenVC;
}

-(LGBloodGlucoseController *)glucoseVC{
    if(!_glucoseVC){
        _glucoseVC = [[LGBloodGlucoseController alloc] init];
        _glucoseVC.patientid = self.patientid;
    }
    return _glucoseVC;
}

-(LGCancerPatientChartController *)weightVC{
    if(!_weightVC){
        _weightVC = [[LGCancerPatientChartController alloc] init];
        _weightVC.chartAction = @"/doctor/patient.Physicalsign/bmiEcharts";
        _weightVC.recordAction = @"/doctor/patient.Physicalsign/bmiList";
        _weightVC.patientid = self.patientid;
        _weightVC.type = @"weight";
    }
    return _weightVC;
}

-(LGCancerPatientSymptomController *)symptomVC{
    if(!_symptomVC){
        _symptomVC = [[LGCancerPatientSymptomController alloc] init];
        _symptomVC.patientid = self.patientid;
    }
    return _symptomVC;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
